<?php
header("Content-type:text/html;charset=utf-8");
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
require_once './include/common.php';
require_once './include/DB.class.php';
require_once './include/OldSoapDiscovery.class.php';


//资产
/*try{

$str=file_get_contents('data.txt');
$config = include_once './config.php';

$xml=simplexml_load_string($str,'SimpleXMLElement',LIBXML_NOCDATA);
if(empty($xml->data)){
	echo show(0,'error',array('msg'=>'数据为空'));
	exit;
}
if(empty($xml->data->asset)){
	echo show(0,'error',array('msg'=>'没有资产'));
	exit;
}

$sqlstr="insert into securitySituationalAwareness.asset(code,area,dip,dmac,dname,dmanufacturers,dtype,dmodel,businesstypes,system,agent) values";
$temp=array();
foreach ($xml->data->asset as $v) {
	$temp[]=((array)$v);
}
foreach ($temp as $v) {
	$sqlstr.='("'.implode('","',$v['field']).'"),';
}
$sqlstr=substr($sqlstr, 0, -1);
$sqlstr.=';';


$db = DB::getInstance($config['host'],$config['user'],$config['password'],$config['database'],$config['character']);
$flag = $db->execSql($sqlstr);

if(!empty($flag)){
	echo show(1,'success',array('msg'=>'录入成功'));
}else{
	echo show(0,'error',array('msg'=>'录入失败'));
}

}catch(\Exception $e){
	echo show(0,'failed',array('msg'=>$e->getMessage()));
}*/


//事件
/*try{
			$str=file_get_contents('event.txt');
			$config = include_once './config.php';

			$xml=simplexml_load_string($str,'SimpleXMLElement',LIBXML_NOCDATA);
			if(empty($xml->data)){
				echo show(0,'error',array('msg'=>'数据为空'));
				exit;
			}
			if(empty($xml->data->event)){
				echo show(0,'error',array('msg'=>'没有事件'));
				exit;
			}
			$sqlstr="insert into event(`code`,`area`,`monitoringdevice`,`sourceip`,`purposeip`,`name`,`describe`,`etime`,`repeat`,`status`) values";
			$temp=array();
			foreach ($xml->data->event as $v) {
				$temp[]=((array)$v);
			}
			foreach ($temp as $v) {
				$sqlstr.='("'.implode('","',$v['field']).'"),';
			}
			$sqlstr=substr($sqlstr, 0, -1);
			$sqlstr.=';';
			$flag = DB::getInstance($config['host'],$config['user'],$config['password'],$config['database'],$config['character'])->execSql($sqlstr);
			if(!empty($flag)){
				echo show(1,'success',array('msg'=>'录入成功'));
			}else{
				echo show(0,'error',array('msg'=>'录入失败'));
			}

			}catch(\Exception $e){
				echo show(0,'failed',array('msg'=>$e->getMessage()));
			}*/


//alarm
try{
			$str=file_get_contents('alarm.txt');
			$config = include_once './config.php';

			$xml=simplexml_load_string($str,'SimpleXMLElement',LIBXML_NOCDATA);
			if(empty($xml->data)){
				echo show(0,'error',array('msg'=>'数据为空'));
				exit;
			}
			if(empty($xml->data->warn)){
				echo show(0,'error',array('msg'=>'没有告警'));
				exit;
			}
			$sqlstr="insert into alarm(`code`,`area`,`monitoringdevice`,`sourceip`,`purposeip`,`name`,`describe`,`atime`,`repeat`,`status`) values";
			$temp=array();
			foreach ($xml->data->warn as $v) {
				$temp[]=((array)$v);
			}
			foreach ($temp as $v) {
				$sqlstr.='("'.implode('","',$v['field']).'"),';
			}
			$sqlstr=substr($sqlstr, 0, -1);
			$sqlstr.=';';
			$flag = DB::getInstance($config['host'],$config['user'],$config['password'],$config['database'],$config['character'])->execSql($sqlstr);
			if(!empty($flag)){
				echo show(1,'success',array('msg'=>'录入成功'));
			}else{
				echo show(0,'error',array('msg'=>'录入失败'));
			}


			}catch(\Exception $e){
				echo show(0,'failed',array('msg'=>$e->getMessage()));
			}
?>